Skip to content

[FEATURE] add time_window for SignalObj - #49

Open
aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-time_window
Open

aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-time_window

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

Adds pytta.time_window(signalObj, interval, unit='time', window='hann', symmetric=False).

The window is built from pairs of bounds. start <= end is a fade out (ones, falling half window, zeros); start > end is a fade in; several pairs multiply, so the usual impulse response window is [fadeInEnd, 0, fadeOutStart, fadeOutEnd]. symmetric=True mirrors the window about the centre of the signal, for slightly non causal impulse responses. Bounds are given in seconds or in zero based samples. The slope has abs(end - start) + 1 samples and is one half of a symmetric window twice as long, so a hann slope ends at exactly zero. The input is not modified; a new SignalObj with the same metadata is returned.

The behaviour follows ita_time_window of the ITA-Toolbox (RWTH Aachen), except that the bounds are not moved to even sample numbers. The implementation is written from the documented behaviour; no ITA code is copied.

Tests (tests/test_time_window.py, 9 tests):

  • shape of the falling slope against the analytic symmetric Hann formula
  • fade in as the mirror image of the fade out
  • composition of several pairs by product
  • rectangular window as a hard cut
  • seconds to samples conversion
  • symmetric option
  • new object, metadata kept, every channel windowed the same way
  • rejection of invalid interval, unit and window
  • sample by sample comparison with the ITA-Toolbox on five cases (fade out, fade in, both ends with hann and with rectwin, symmetric). Reference data: tests/golden/time_window_ita.mat (79 kB), generated by tests/golden/make_time_window_ita.m with MATLAB and the ITA-Toolbox. Measured difference: 5e-8 of the signal peak, the float32 floor of SignalObj.

Checked with Python 3.12, numpy 1.26, scipy 1.17. The existing tests behave as on development: the 7 failures there (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change. NumPy 2 support is in #53.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

Apply a time window built from pairs of bounds: start <= end fades out
(ones, falling half window, zeros), start > end fades in, several pairs
multiply, and symmetric mirrors the window about the centre of the
signal. Bounds in seconds or zero based samples; the slope has
abs(end - start) + 1 samples and is one half of a symmetric window twice
as long, so a hann slope ends at exactly zero.

Follows ita_time_window of the ITA-Toolbox (RWTH Aachen), without the
move of the bounds to even sample numbers. Tests pin each rule on a
signal of ones and compare five cases sample by sample with the
ITA-Toolbox output stored in tests/golden/time_window_ita.mat, which
tests/golden/make_time_window_ita.m regenerates with MATLAB.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant